//plan.js
//加载高德地图sdk
var amapFile = require('../../libs/amap-wx.js');

//使用我的key
var config = require('../../libs/config.js');

var lonlat;
var city;
Page({
	data: {
		tips: {},
		val:"" ,//输入框默认值
		weather: {} //今日天气
	},
	onLoad: function(e) {
		lonlat = e.lonlat;
		city = e.city;
		
		//查询今日的天气
		var that = this;
		var key = config.Config.key;
		var myAmapFun = new amapFile.AMapWX({key: key});
		myAmapFun.getWeather({
		  success: function(data){
		    that.setData({
		      weather: data
		    });
		  },
		  fail: function(info){
		    // wx.showModal({title:info.errMsg})
		  }
		})
	},
	onShow:function(){
		this.clearInput();
		//当显示
		wx.showToast({
			title: '您使用的是beta版，该功能暂时只支持体验！',
			icon: 'none',
			duration: 3000, //延迟时间
		})
	},
	clearInput(){
		//清空输入结果
		this.setData({
			tips: {},
			val:""
		});
	},
	bindInput: function(e) {
		//当用户删掉输入的内容时
		if(e.detail.value==""){
			this.clearInput();
		}
		var that = this;
		var keywords = e.detail.value;
		var key = config.Config.key;
		var myAmapFun = new amapFile.AMapWX({
			key: key
		});
		myAmapFun.getInputtips({
			keywords: keywords,
			location: lonlat,
			city: city,
			success: function(data) {
				//console.log(data);
				if (data && data.tips) {
					that.setData({
						tips: data.tips
					});
				}
			}
		})
	},
	bindSearch: function(e) {
		if(e.target.dataset.location==""){
			wx.showToast({
				title: '暂不支持异地规划！',
				icon: 'none',
				duration: 1000,
			})
			return false;
		}else{
			//当没有返回地址得时候
			//发送名称
			// var keywords = e.target.dataset.keywords;
			// var url = '../query/query?name=' + keywords;
			// wx.redirectTo({
			// 	url: url
			// })
			// 发送坐标
			// var keywords = e.target.dataset.location;
			// var url = '../query/query?name=' + keywords;
			// wx.navigateTo({
			// 	url: url
			// })
			
			var url = '../article/article';
			wx.navigateTo({
				url: url
			})
		}
	},
	onShareAppMessage: function () {
	    return {
	        title: '欢迎使用面试精灵！',
	        desc: '导航和日程记录，让面试简单化！',
	        path: '/pages/index/index'
	    }
	}
})
